package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.entity.jobs;
import com.example.springboot.entity.students;
import com.example.springboot.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 个人信息管理Controller
 *
 * @author 柏旭东
 * @date 2024-6-15
 */

@CrossOrigin(origins = "http://localhost:7070")
@RestController
@RequestMapping("/Student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    /*
     * 所有学生信息
     */
    @GetMapping("/selectAll")
    public Result selectAll() {
        List<students> studentsList = studentService.findAll();
        return Result.success(studentsList);
    }

    /*
     * 根据学生id查询学生信息
     */
    @GetMapping("/selectByStudentId")
    public Result selectByStudentId(@RequestParam Integer user_id) {
        System.out.println(user_id);
        List<students> studentsList = studentService.selectByStudentId(user_id);
        return Result.success(studentsList);
    }

//    /*
//     * 根据学生姓名查询学生信息
//     */
//    @GetMapping("/selectByName")
//    public Result selectByName(@RequestParam String studentName) {
//        System.out.println(studentName);
//        List<students> studentsList = studentService.selectByName(studentName);
//        return Result.success(studentsList);
//    }

    /*
     * 删除学生信息
     */
    @DeleteMapping("/delete/{student_id}")
    public String deleteStu(@PathVariable int student_id) {
        studentService.deleteStu(student_id);
        return "User record deleted successfully!";
    }

    /*
     * 添加学生信息
     */
    @PostMapping("/addStudent")
    public Result addStudent(@RequestBody students student) {
        studentService.addStudent(student);
        return Result.success("添加成功");
    }


    /*
     * 修改学生信息
     */
    @PutMapping ("/edit")
    public Result updateStudent(@RequestBody students students) {
        studentService.updateStudent(students);
        return Result.success("修改成功");
    }


}
